package main

import (
	"fmt"
	"github.com/gorilla/sessions"
	"net/http"
	"studygin/routers"
)

var store = sessions.NewCookieStore([]byte("session-secret"))

func main() {
	http.HandleFunc("/save", func(w http.ResponseWriter, req *http.Request) {
		session, err := store.Get(req, "session")
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		session.Values["foo"] = "bar"
		session.Values[42] = 43
		err = session.Save(req, w)
		if err != nil {
			return
		}
	})
	http.HandleFunc("/get", func(w http.ResponseWriter, req *http.Request) {
		session, err := store.Get(req, "session-name")
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		foo := session.Values["foo"]
		fmt.Println(foo)
	})
	engine := routers.SetupRouter()
	routers.LoadIndex(engine)
	routers.LoadUpload(engine)
	routers.LoadGroup(engine)
	routers.LoadUser(engine)
	routers.LoadLogin(engine)
	routers.LoadResp(engine)
	routers.LoadCookie(engine)
	routers.Download(engine)
	if err := engine.Run(":8081"); err != nil {
		fmt.Println("startup error")
	}
}
